//初始化
var form;
var $;
var element;
layui.use(['element','form'],function(){
    form = layui.form;
    $ = layui.jquery;
    element = layui.element;
    load();
    setNums();
    getEchartsUserInfo();
    window.setInterval(getEchartsUserInfo,300000);
    window.setInterval(setNums,300000);
});
function load(){
    $(".tit_btn").bind('click',function(){
        location.reload();
    })
    $(".tit_btn2").bind('click',function(){
        window.history.go(-1);  //返回上一页
    })
}
function setNums(){
    $.get("/personnel/selUserNum", function (res) {
        $(".backNum").html(res.afterUserNum);
        $(".beforeNum").html(res.userNum);
    });
}
function getEchartsUserInfo(){
    $.get("/personnel/selBeforeNum", function (res) {
        $.get("/personnel/selBackNum", function (data) {
            getEcharts(data.obj,res.obj);
        });
    });
}
function getEcharts(data,item){
    var chartDom = document.getElementById('userecharts');
    var myChart = echarts.init(chartDom);
    var option;

    option = {
        title: {
            text: '用户统计图',
            subtext: '思云产品'
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['前端用户总数', '管理人员总数']
        },
        toolbox: {
            show: true,
            feature: {
                dataView: {show: true, readOnly: false},
                magicType: {show: true, type: ['line', 'bar']},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        calculable: true,
        xAxis: [
            {
                type: 'category',
                data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '前端用户总数',
                type: 'bar',
                data: item,
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            },
            {
                name: '管理人员总数',
                type: 'bar',
                data: data,
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            }
        ]
    };
    option && myChart.setOption(option);
    window.onresize = myChart.resize;
}